package top.infopub.mgr.fia.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.fia.dao.LandProfitDao;
import top.infopub.mgr.fia.domain.LandProfitDomain;
import top.infopub.mgr.fia.service.LandProfitService;
import top.infopub.mgr.fia.vo.LandProfitVo;
import top.infopub.model.fia.LandProfit;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.security.vo.AuthorizationVO;
import top.infopub.tdp.sys.service.CodeGeneratorConfigService;
import top.infopub.tdp.util.BizParaUtil;
import top.infopub.util.IdFactory;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Service
public class LandProfitServiceImpl extends GenericServiceImpl<LandProfit, String> implements
		LandProfitService {

	@Autowired
	private LandProfitDao landProfitDao;
	
	@Autowired
    private CodeGeneratorConfigService codeGeneratorConfigService;

	@Override
	public GenericDao<LandProfit, String> getDao() {
		return landProfitDao;
	}

    @Override
    public Page<LandProfitDomain> selectPageByDomainWhere(Page<LandProfitDomain> page,
                                                          LandProfitVo landProfitVo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        Page<LandProfitDomain> lan = landProfitDao.selectByDomainWhere(landProfitVo);
        return lan;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveLandProFit(LandProfit landProfit) {
        String codes = codeGeneratorConfigService.generatorCode("fia_land_profit");  //需要在系统进行编号配置的
        String hrOrgBillId = BizParaUtil.get("land_org_id");
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        
        landProfit.setId(IdFactory.getUUIDUpper());
        landProfit.setCodes(codes);
        landProfit.setHrOrgBillId(hrOrgBillId);
        landProfit.setAddBy(vo.getId());
        landProfit.setAddTime(top.infopub.mgr.util.DateUtils.getCurrentDateTime());
        landProfit.setUptBy(vo.getId());
        landProfit.setUptTime(top.infopub.mgr.util.DateUtils.getCurrentDateTime());
        landProfit.setState(1); //已登记
        landProfitDao.insert(landProfit);
        
    }

    @Override
    public Boolean changeState(String id,  int state) {
        return  landProfitDao.changeState(id,state);
    }

    @Override
    public LandProfitDomain queryDomainById(String id) {
        return landProfitDao.queryDomainById(id);
    }

}